package com.feng.config;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Description:
 * User: zhangyinglong
 * Date: 2021-04-25
 * Time: 14:26
 */
@Controller
public class RedirectController {

    @GetMapping("/baidu")
    public String redirect(){
        return "redirect:http://baidu.com";
    }

    @GetMapping("/baidu1")
    public void redirect1(HttpServletResponse response){
        try {
            response.sendRedirect("http://baidu.com");
        } catch (IOException e) {
        }
    }
    @GetMapping("/baidu2")
    public ModelAndView redirect2(String userName){
        ModelAndView  model = new ModelAndView("redirect:http://baidu.com");
        return model;
    }

    // 返回 RedirectView 对象
    @GetMapping("/baidu3")
    public RedirectView redirect3() {
        return new RedirectView("http://baidu.com");
    }


    @GetMapping("/baidu4")
    public String forward(){

//        return "forward:http://baidu.com";//无法转发地址

        return "forward:/baidu3";
    }


}
